<?php

namespace App\Models\Log;

use App\Models\GameList;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Notifications\Notifiable;

use App\Models\Conf\Site;
use App\Models\Def\MainGamePlat;
use App\Models\Def\Game;
use App\Models\Inf\Player;

class PlayerBetFlow extends Model
{
    use Notifiable;

    protected static function boot()
    {
        parent::boot();
    }

    public $table = 'log_player_bet_flow';

    const CREATED_AT = 'created_at';

    const UPDATED_AT = 'updated_at';

    public $guarded = [];


    public static $rules = [];

    public function Player()
    {
        return $this->belongsTo(Player::class, 'username', 'username');
    }

    public function game()
    {
        $game = GameList::where(
            [
                ['record_match_code', '=', $this->game_code],
                ['main_game_plat_code', '=', $this->main_game_plat_code],
            ]
        )->get();
        if ($game->count() > 1) {
            $game = GameList::where([
                    ['record_match_code', '=', $this->game_code],
                    ['main_game_plat_code', '=', $this->main_game_plat_code],
                    ['record_match_deputy_code', '=', $this->lobby_type],
                ]
            )->first();
        } elseif ($game->count() == 1) {
            $game = GameList::where(
                [
                    ['record_match_code', '=', $this->game_code],
                    ['main_game_plat_code', '=', $this->main_game_plat_code],
                ]
            )->first();
        } else {
            $game = GameList::where(
                [
                    ['pc_game_code', '=', $this->game_code],
                    ['main_game_plat_code', '=', $this->main_game_plat_code],
                ]
            )->first();
            if (empty($game)) {
                $game = GameList::where(
                    [
                        ['mobile_game_code', '=', $this->game_code],
                        ['main_game_plat_code', '=', $this->main_game_plat_code],
                    ]
                )->first();
            }
        }

        if (empty($game)) {
            $game = GameList::where(
                [
                    ['record_match_code', '=', $this->game_code],
                    ['main_game_plat_code', '=', $this->main_game_plat_code],
                ]
            )->first();
        }

        return $game;
    }


}
